
// 注册页面的js
Page({
  data: {
    username: '',
    mobile: '',
    password: '',
    confirmPass: ''
  },
  
  usernameInput(e) {
    this.setData({
      username: e.detail.value
    });
  },
  mobileInput(e) {
    this.setData({
      mobile: e.detail.value
    });
  },
  passwordInput(e) {
    this.setData({
      password: e.detail.value
    });
  },
  confirmPassInput(e) {
    this.setData({
      confirmPass: e.detail.value
    });
  },
  register() {
    // console.log(this.data.username,'01');
    // console.log(this.data.mobile,'02');
    // console.log(this.data.password,'03');
    // console.log(this.data.confirmPass,'04');
    if (!this.data.username || !this.data.mobile || !this.data.password || !this.data.confirmPass) {
      wx.showToast({
        title: "请填写完整信息",
        icon: "none"
      });
      return;
    }
    if (this.data.password !== this.data.confirmPass) {
      wx.showToast({
        title: "两次输入的密码不一致",
        icon: "none"
      });
      return;
    }
    wx.request({
      url: "http://localhost:8001/goods/user/registered",
      method: "POST",
      data: {
        username: this.data.username,
        mobile: this.data.mobile,
        password: this.data.password
      },
      success: res => {
        console.log(res);
        if (res.data.code === 20000) {
          wx.showToast({
            title: "注册成功",
            icon: "success"
          });
          wx.navigateTo({
            url: "/pages/login/index"
          });
        } else {
          wx.showToast({
            title: res.data.message,
            icon: "none"
          });
        }
      },
      fail: err => {
        console.error(err);
      }
    });
  }
});

